#define DEBUG
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

const int maxn=100, maxm=2000, maxc=100;

double sqr(double x) {
  return x*x;
}

class Side {
public:
  int u, v, c;
  double d;

  static bool cmp(Side a, Side b) {
    return a.d<b.d;
  }
};

void initSet(int *f, int n) {
  for (int i=0; i<=n; i++) {
    f[i] = i;
  }
}

int getFa(int *f, int o) {
  return o==f[o] ? o : f[o]=getFa(f, f[o]);
}

void merge(int *f, int a, int b) {
  int x=getFa(f, a), y=getFa(f, b);
  if (x!=y) {
    f[y] = x;
  }
}

long double getAns(Side *s, int n, int m) {
  sort(s+1, s+m+1, Side::cmp);

  static int set[maxn+1];
  initSet(set, n);
  int sum=0, sumq=0;
  for (int i=1; i<=m; i++) {
    if (getFa(set, s[i].u)!=getFa(set, s[i].v)) {
      merge(set, s[i].u, s[i].v);
      sum += s[i].c;
      sumq += sqr(s[i].c);
    }
  }

  return sqrt((sumq-sqr(sum)/(n-1))/(n-1));
}

int main() {
#ifdef DEBUG
  freopen("3410.in", "r", stdin);
  freopen("3410.out", "w", stdout);
#endif

  static Side sides[maxm+1];
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i=1; i<=m; i++) {
    scanf("%d %d %d", &sides[i].u, &sides[i].v, &sides[i].c);
  }

  long double ans=1e9;
  for (double i=0; i<=maxc; i+=0.25) {
    static Side temp[maxm+1];
    for (int j=1; j<=m; j++) {
      temp[j].u = sides[j].u, temp[j].v = sides[j].v, temp[j].c=sides[j].c;
      temp[j].d = sqr(sides[j].c-i);
    }
    ans = min(ans, getAns(temp, n, m));
  }
  printf("%.4LF", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
